package com.example.jetpack04.viewmodel;

import android.util.Log;

import androidx.databinding.ObservableField;

import com.example.jetpack04.model.User;

public class UserViewModel {

    private ObservableField<User> user ;

    public UserViewModel() {
        if (user == null){
            user=new ObservableField<>();
            user.set(new User("xiaoluoi" ,11 , "SIT"));
        }
    }


    public User getUser(){
        return user.get();
    }

    public void setUser(User user){
        Log.d("msg", "检测到数据变化了");
        this.user.set(user);
    }

    public String  getUserName(){
        return user.get().name;
    }

    public void setUserName(String userName){
        Log.i("msg" , "set user name : "+userName);
        user.get().name = userName;
    }
}
